package com.smart.community.community.service;

import com.baomidou.mybatisplus.extension.service.IService;
import com.smart.community.commons.result.PageResult;
import com.smart.community.community.entity.Community;

import java.math.BigDecimal;
import java.util.List;

/**
 * 社区管理Service接口
 * 继承基础Service接口，提供社区相关的业务操作
 * 
 * @author Wu.Liang
 * @since 2024-12-19
 * @version 1.0.0
 */
public interface ICommunityService extends IService<Community> {
    
    /**
     * 分页查询社区（支持多条件搜索）
     * 
     * @param current       当前页
     * @param size          每页大小
     * @param keyword       关键词（搜索社区名称、社区编码、地址）
     * @param regionId      区域ID
     * @param communityType 社区类型
     * @param status        状态
     * @return 分页结果
     */
    PageResult<Community> pageCommunities(Integer current, Integer size, String keyword,
                                         Long regionId, Integer communityType, Integer status);
    
    /**
     * 根据区域ID查询社区列表
     * 
     * @param regionId 区域ID
     * @return 社区列表
     */
    List<Community> listByRegionId(Long regionId);
    
    /**
     * 根据负责人姓名查询社区列表
     * 
     * @param managerName 负责人姓名
     * @return 社区列表
     */
    List<Community> listByManagerName(String managerName);
    
    /**
     * 根据社区类型查询社区列表
     * 
     * @param communityType 社区类型
     * @return 社区列表
     */
    List<Community> listByCommunityType(Integer communityType);
    
    /**
     * 根据状态查询社区列表
     * 
     * @param status 状态(0-禁用,1-启用)
     * @return 社区列表
     */
    List<Community> listByStatus(Integer status);
    
    /**
     * 获取所有启用的社区
     * 
     * @return 启用的社区列表
     */
    List<Community> listEnabledCommunities();
    
    /**
     * 根据社区编码查询社区
     * 
     * @param communityCode 社区编码
     * @return 社区信息
     */
    Community getByCommunityCode(String communityCode);
    
    /**
     * 根据社区名称查询社区
     * 
     * @param communityName 社区名称
     * @return 社区信息
     */
    Community getByCommunityName(String communityName);
    
    /**
     * 根据坐标和距离搜索附近的社区
     * 
     * @param longitude 经度
     * @param latitude  纬度
     * @param distance  距离(千米)
     * @return 社区列表
     */
    List<Community> searchNearby(BigDecimal longitude, BigDecimal latitude, Double distance);
    
    /**
     * 验证社区编码是否已存在
     * 
     * @param communityCode 社区编码
     * @return 是否已存在
     */
    boolean isCommunityCodeExists(String communityCode);
    
    /**
     * 验证社区名称是否已存在
     * 
     * @param communityName 社区名称
     * @return 是否已存在
     */
    boolean isCommunityNameExists(String communityName);
    
    /**
     * 为社区设置负责人
     * 
     * @param communityId 社区ID
     * @param managerName 负责人姓名
     * @return 是否设置成功
     */
    boolean assignManager(Long communityId, String managerName);
    
    /**
     * 移除社区负责人
     * 
     * @param communityId 社区ID
     * @return 是否移除成功
     */
    boolean removeManager(Long communityId);
    
    /**
     * 启用社区
     * 
     * @param communityId 社区ID
     * @return 是否操作成功
     */
    boolean enableCommunity(Long communityId);
    
    /**
     * 禁用社区
     * 
     * @param communityId 社区ID
     * @return 是否操作成功
     */
    boolean disableCommunity(Long communityId);
    
    /**
     * 更新社区统计信息
     * 
     * @param communityId 社区ID
     * @return 是否更新成功
     */
    boolean updateCommunityStatistics(Long communityId);
    
    /**
     * 批量更新社区统计信息
     * 
     * @param communityIds 社区ID列表
     * @return 是否更新成功
     */
    boolean batchUpdateCommunityStatistics(List<Long> communityIds);
    
    /**
     * 查询社区下的楼栋数量
     * 
     * @param communityId 社区ID
     * @return 楼栋数量
     */
    int getBuildingCount(Long communityId);
    
    /**
     * 查询社区下的住户数量
     * 
     * @param communityId 社区ID
     * @return 住户数量
     */
    int getHouseholdCount(Long communityId);
    
    /**
     * 查询社区下的停车位数量
     * 
     * @param communityId 社区ID
     * @return 停车位数量
     */
    int getParkingCount(Long communityId);
    
    /**
     * 获取社区概览信息
     * 
     * @param communityId 社区ID
     * @return 概览信息
     */
    CommunityOverview getCommunityOverview(Long communityId);
    
    /**
     * 获取社区详细统计信息
     * 
     * @param communityId 社区ID
     * @return 统计信息
     */
    CommunityStatistics getCommunityStatistics(Long communityId);
    
    /**
     * 获取区域下的社区统计
     * 
     * @param regionId 区域ID
     * @return 统计信息
     */
    RegionCommunityStatistics getRegionCommunityStatistics(Long regionId);
    
    /**
     * 批量导入社区
     * 
     * @param communities 社区列表
     * @return 导入结果统计
     */
    ImportResult batchImportCommunities(List<Community> communities);
    
    /**
     * 批量导出社区
     * 
     * @param communityIds 社区ID列表（为空则导出所有）
     * @return 导出数据
     */
    List<Community> batchExportCommunities(List<Long> communityIds);
    
    // ========================= 内部类定义 =========================
    
    /**
     * 社区概览信息内部类
     */
    class CommunityOverview {
        private Long communityId;
        private String communityName;
        private String communityCode;
        private Long regionId;
        private Integer buildingCount;
        private Integer householdCount;
        private Integer parkingCount;
        private Integer residentCount;
        private BigDecimal occupancyRate;
        private BigDecimal parkingOccupancyRate;
        
        public CommunityOverview() {}
        
        // getter/setter methods
        public Long getCommunityId() { return communityId; }
        public void setCommunityId(Long communityId) { this.communityId = communityId; }
        
        public String getCommunityName() { return communityName; }
        public void setCommunityName(String communityName) { this.communityName = communityName; }
        
        public String getCommunityCode() { return communityCode; }
        public void setCommunityCode(String communityCode) { this.communityCode = communityCode; }
        
        public Long getRegionId() { return regionId; }
        public void setRegionId(Long regionId) { this.regionId = regionId; }
        
        public Integer getBuildingCount() { return buildingCount; }
        public void setBuildingCount(Integer buildingCount) { this.buildingCount = buildingCount; }
        
        public Integer getHouseholdCount() { return householdCount; }
        public void setHouseholdCount(Integer householdCount) { this.householdCount = householdCount; }
        
        public Integer getParkingCount() { return parkingCount; }
        public void setParkingCount(Integer parkingCount) { this.parkingCount = parkingCount; }
        
        public Integer getResidentCount() { return residentCount; }
        public void setResidentCount(Integer residentCount) { this.residentCount = residentCount; }
        
        public BigDecimal getOccupancyRate() { return occupancyRate; }
        public void setOccupancyRate(BigDecimal occupancyRate) { this.occupancyRate = occupancyRate; }
        
        public BigDecimal getParkingOccupancyRate() { return parkingOccupancyRate; }
        public void setParkingOccupancyRate(BigDecimal parkingOccupancyRate) { this.parkingOccupancyRate = parkingOccupancyRate; }
    }
    
    /**
     * 社区统计信息内部类
     */
    class CommunityStatistics {
        private Integer totalRooms;
        private Integer occupiedRooms;
        private Integer vacantRooms;
        private Integer totalUnits;
        private Integer totalBuildings;
        private Integer totalParkingSpaces;
        private Integer occupiedParkingSpaces;
        private Integer totalResidents;
        private Integer activeResidents;
        
        public CommunityStatistics() {}
        
        // getter/setter methods
        public Integer getTotalRooms() { return totalRooms; }
        public void setTotalRooms(Integer totalRooms) { this.totalRooms = totalRooms; }
        
        public Integer getOccupiedRooms() { return occupiedRooms; }
        public void setOccupiedRooms(Integer occupiedRooms) { this.occupiedRooms = occupiedRooms; }
        
        public Integer getVacantRooms() { return vacantRooms; }
        public void setVacantRooms(Integer vacantRooms) { this.vacantRooms = vacantRooms; }
        
        public Integer getTotalUnits() { return totalUnits; }
        public void setTotalUnits(Integer totalUnits) { this.totalUnits = totalUnits; }
        
        public Integer getTotalBuildings() { return totalBuildings; }
        public void setTotalBuildings(Integer totalBuildings) { this.totalBuildings = totalBuildings; }
        
        public Integer getTotalParkingSpaces() { return totalParkingSpaces; }
        public void setTotalParkingSpaces(Integer totalParkingSpaces) { this.totalParkingSpaces = totalParkingSpaces; }
        
        public Integer getOccupiedParkingSpaces() { return occupiedParkingSpaces; }
        public void setOccupiedParkingSpaces(Integer occupiedParkingSpaces) { this.occupiedParkingSpaces = occupiedParkingSpaces; }
        
        public Integer getTotalResidents() { return totalResidents; }
        public void setTotalResidents(Integer totalResidents) { this.totalResidents = totalResidents; }
        
        public Integer getActiveResidents() { return activeResidents; }
        public void setActiveResidents(Integer activeResidents) { this.activeResidents = activeResidents; }
    }
    
    /**
     * 区域社区统计内部类
     */
    class RegionCommunityStatistics {
        private Integer totalCommunities;
        private Integer activeCommunities;
        private Integer inactiveCommunities;
        private Integer residentialCommunities;
        private Integer commercialCommunities;
        private Integer officeCommunities;
        private Integer mixedCommunities;
        private Integer totalResidents;
        private Integer activeResidents;
        
        public RegionCommunityStatistics() {}
        
        // getter/setter methods
        public Integer getTotalCommunities() { return totalCommunities; }
        public void setTotalCommunities(Integer totalCommunities) { this.totalCommunities = totalCommunities; }
        
        public Integer getActiveCommunities() { return activeCommunities; }
        public void setActiveCommunities(Integer activeCommunities) { this.activeCommunities = activeCommunities; }
        
        public Integer getInactiveCommunities() { return inactiveCommunities; }
        public void setInactiveCommunities(Integer inactiveCommunities) { this.inactiveCommunities = inactiveCommunities; }
        
        public Integer getResidentialCommunities() { return residentialCommunities; }
        public void setResidentialCommunities(Integer residentialCommunities) { this.residentialCommunities = residentialCommunities; }
        
        public Integer getCommercialCommunities() { return commercialCommunities; }
        public void setCommercialCommunities(Integer commercialCommunities) { this.commercialCommunities = commercialCommunities; }
        
        public Integer getOfficeCommunities() { return officeCommunities; }
        public void setOfficeCommunities(Integer officeCommunities) { this.officeCommunities = officeCommunities; }
        
        public Integer getMixedCommunities() { return mixedCommunities; }
        public void setMixedCommunities(Integer mixedCommunities) { this.mixedCommunities = mixedCommunities; }
        
        public Integer getTotalResidents() { return totalResidents; }
        public void setTotalResidents(Integer totalResidents) { this.totalResidents = totalResidents; }
        
        public Integer getActiveResidents() { return activeResidents; }
        public void setActiveResidents(Integer activeResidents) { this.activeResidents = activeResidents; }
    }
    
    /**
     * 导入结果内部类
     */
    class ImportResult {
        private int totalCount;
        private int successCount;
        private int failCount;
        private List<String> errors;
        
        public ImportResult(int totalCount, int successCount, int failCount, List<String> errors) {
            this.totalCount = totalCount;
            this.successCount = successCount;
            this.failCount = failCount;
            this.errors = errors;
        }
        
        // getter methods
        public int getTotalCount() { return totalCount; }
        public int getSuccessCount() { return successCount; }
        public int getFailCount() { return failCount; }
        public List<String> getErrors() { return errors; }
    }
}
